package tarefas;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;

import com.cloudgarden.resource.SWTResourceManager;

public class App extends org.eclipse.swt.widgets.Composite {

	private Menu menu1;
	private MenuItem aboutMenuItem;
	private MenuItem contentsMenuItem;
	private Menu helpMenu;
	private MenuItem helpMenuItem;
	private MenuItem exitMenuItem;
	private MenuItem closeFileMenuItem;
	private MenuItem saveFileMenuItem;
	private MenuItem newFileMenuItem;
	private MenuItem openFileMenuItem;
	private Menu fileMenu;
	private MenuItem fileMenuItem;

	{
		//Register as a resource user - SWTResourceManager will
		//handle the obtaining and disposing of resources
		SWTResourceManager.registerResourceUser(this);
	}

	public App(Composite parent, int style) {
		super(parent, style);
		initGUI();
	}
	
	/**
	* Initializes the GUI.
	*/
	private void initGUI() {
		this.setSize(new org.eclipse.swt.graphics.Point(400,300));
		this.setBackground(SWTResourceManager.getColor(192, 192, 192));
		FormLayout thisLayout = new FormLayout();
		this.setLayout(thisLayout);
		{
			menu1 = new Menu(getShell(), SWT.BAR);
			getShell().setMenuBar(menu1);
			{
				fileMenuItem = new MenuItem(menu1, SWT.CASCADE);
				fileMenuItem.setText("File");
				{
					fileMenu = new Menu(fileMenuItem);
					{
						openFileMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
						openFileMenuItem.setText("Open");
					}
					{
						newFileMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
						newFileMenuItem.setText("New");
					}
					{
						saveFileMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
						saveFileMenuItem.setText("Save");
					}
					{
						closeFileMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
						closeFileMenuItem.setText("Close");
					}
					{
						exitMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
						exitMenuItem.setText("Exit");
					}
					fileMenuItem.setMenu(fileMenu);
				}
			}
			{
				helpMenuItem = new MenuItem(menu1, SWT.CASCADE);
				helpMenuItem.setText("Help");
				{
					helpMenu = new Menu(helpMenuItem);
					{
						contentsMenuItem = new MenuItem(helpMenu, SWT.CASCADE);
						contentsMenuItem.setText("Contents");
					}
					{
						aboutMenuItem = new MenuItem(helpMenu, SWT.CASCADE);
						aboutMenuItem.setText("About");
					}
					helpMenuItem.setMenu(helpMenu);
				}
			}
		}
		this.layout();
		
	}
	
	/**
	* Auto-generated main method to display this 
	* org.eclipse.swt.widgets.Composite inside a new Shell.
	*/
	public static void main(String[] args) {
		Display display = Display.getDefault();
		Shell shell = new Shell(display);
		App inst = new App(shell, SWT.NULL);
		Point size = inst.getSize();
		shell.setLayout(new FillLayout());
		shell.layout();
		if(size.x == 0 && size.y == 0) {
			inst.pack();
			shell.pack();
		} else {
			Rectangle shellBounds = shell.computeTrim(0, 0, size.x, size.y);
			shell.setSize(shellBounds.width, shellBounds.height);
		}
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
	}

}
